<%@ WebHandler Language="C#" Class="filedownload" %>  
using System;  
using System.Web;  
using System.Data.SqlClient;  
using System.Data;  
using System.IO;  
using System.Configuration;  

  
public class filedownload : IHttpHandler  
{
    public void ProcessRequest(HttpContext context)
    {
        string ID = context.Request.QueryString["ID"] as string;

        SqlDataReader dr = (new UDS.Components.HR()).GetFileInfo(ID);

            if (dr.Read())
            {
                string filename = dr["HR_Path"].ToString();
                context.Response.Buffer = true;
                context.Response.Clear();
                context.Response.ContentType = "application/download";
                context.Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ";");
                context.Response.BinaryWrite(File.ReadAllBytes(context.Server.MapPath(string.Format(@"Attachment\{0}", filename))));
                context.Response.Flush();
                context.Response.End();
            }
            dr.Close();
    }
    public bool IsReusable  
    {  
        get  
        {  
            return false;  
        }  
    }  
  
}  